import java.util.*;

public class Fuzzy{

	static HashMap<String,String> table = new HashMap<String,String>();

	public static void main(String[] args){
		String testString;
		String testType;
		if (args.length > 1){
			testString = args[0];
			testType = args[1];
		}else{
			testString = "Hello";
			testType = "int";
		}
		table.put("xint","int");
		table.put("x1","int");
		table.put("y1","int");
		table.put("z32","int");
		table.put("xstr","string");

		System.out.println(fuzzyLookup(testString, testType));
	}

	public static String fuzzyLookup(String testString, String testType){
		HashSet<String> permutations = new HashSet<String>();
		String match = "";

		if(testString.length() < 2){
			permutations.add(testString);
			match = reallyFuzzyLookup(permutations,testType);
			return (match.equals("")) ? "NO APPLICABLE MATCH" : match;
		}
		
		permuteString("", testString, permutations);

		match = fuzzyLookup(permutations, testType);
		if(!match.equals(""))
			return match;

		for(int i = 0; i < testString.length(); i++)
			permuteString("",testString.replaceFirst(Character.toString(testString.charAt(i)),""),permutations);

		match = fuzzyLookup(permutations, testType);
		if(!match.equals(""))
			return match;
		
		match = reallyFuzzyLookup(permutations, testType);
		return (match.equals("")) ? "NO APPLICABLE MATCH" : match;
	}

	public static String fuzzyLookupTypeless(String testString){
		HashSet<String> permutations = new HashSet<String>();
		String match = "";

		if(testString.length() < 2){
			permutations.add(testString);
			match = reallyFuzzyLookupTypeless(permutations);
			return (match.equals("")) ? "NO APPLICABLE MATCH" : match;
		}
		
		permuteString("", testString, permutations);

		match = fuzzyLookupTypeless(permutations);
		if(!match.equals(""))
			return match;

		for(int i = 0; i < testString.length(); i++)
			permuteString("",testString.replaceFirst(Character.toString(testString.charAt(i)),""),permutations);

		match = fuzzyLookupTypeless(permutations);
		if(!match.equals(""))
			return match;
		
		match = reallyFuzzyLookupTypeless(permutations);
		return (match.equals("")) ? "NO APPLICABLE MATCH" : match;
	}

	public static void permuteString(String beginningString, String endingString, HashSet<String> strings){
		if (endingString.length() <= 1){
			strings.add((beginningString + endingString).toLowerCase());
		}
		else{
			for (int i = 0; i < endingString.length(); i++){
				String newString = endingString.substring(0, i) + endingString.substring(i + 1);
				permuteString(beginningString + endingString.charAt(i), newString, strings);
			}
		}
	}

	public static String fuzzyLookup(HashSet<String> permutations, String type){
		for(String permutation : permutations)
			for(String tableString : table.keySet())
				if(table.get(tableString).toLowerCase().equals(type.toLowerCase())
							&& tableString.toLowerCase().equals(permutation))
					return tableString;
		return "";
	}

	public static String reallyFuzzyLookup(HashSet<String> permutations, String type){
		for(String permutation : permutations)
			for(String tableString : table.keySet())
				if(table.get(tableString).toLowerCase().equals(type.toLowerCase())
							&& tableString.toLowerCase().contains(permutation))
					return tableString;
		return "";
	}
	
	public static String fuzzyLookupTypeless(HashSet<String> permutations){
		for(String permutation : permutations)
			for(String tableString : table.keySet())
				if(tableString.toLowerCase().equals(permutation))
					return tableString;
		return "";
	}

	public static String reallyFuzzyLookupTypeless(HashSet<String> permutations){
		for(String permutation : permutations)
			for(String tableString : table.keySet())
				if(tableString.toLowerCase().contains(permutation))
					return tableString;
		return "";
	}
}
